﻿Public Partial Class EditMaterialEstimate
    Inherits System.Web.UI.Page

    Dim clsGet As New ClassFunctionGetData
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not (Session("indexPopupTariff") Is Nothing) Then
            Dim Index As Integer = Session("indexPopupTariff")
            Dim ds As DataSet = Session("MAT_USE")
            If ViewState("Index") Is Nothing Then
                txtAmount.Text = ds.Tables(0).Rows(Index).Item("Count") & ""
            End If
            lbMeterial.Text = ds.Tables(0).Rows(Index).Item("MATERIAL") & ""
            lbName.Text = ds.Tables(0).Rows(Index).Item("Text_Line") & ""
            ViewState("Index") = Index
        End If
    End Sub

    Private Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Session("indexPopupTariff") = Nothing
        ViewState("Index") = Nothing
        ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " parent.closeModalPopup('N');", True)
    End Sub

    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If (txtAmount.Text.Trim() = "") Then
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('กรุณาทำการระบุจำนวน');", True)
            Exit Sub
        End If
        Dim Index As Integer = ViewState("Index")
        Dim ds As DataSet = Session("MAT_USE")
        ds.Tables(0).Rows(Index).Item("Count") = txtAmount.Text
        ds.Tables(0).AcceptChanges()
        Session("MAT_USE") = ds
        Session("indexPopupTariff") = Nothing
        ViewState("Index") = Nothing
        ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", " parent.closeModalPopup('S');", True)
    End Sub


    Private Sub MainPage_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        Dim ds As DataSet = Session("UserData")
        If Not (ds Is Nothing) Then
            Page.MasterPageFile = clsGet.GetMaster_Page(ds.Tables(0).Rows(0).Item("User_Name").ToString(), "")
        End If
    End Sub
End Class